<?php
/**
 * Joomla! 1.5 component Joomla Community Polls
 *
 * @version $Id: controller.php 2009-08-10 03:45:15 svn $
 * @author Maverick
 * @package Joomla
 * @subpackage Joomla Community Polls
 * @license GNU/GPL
 *
 * The Joomla Community Polls allows the members of the Joomla website to create and manage polls from the front-end.
 * The administrator has the powerful tools provided in the back-end to manage the polls published by all users.
 */

defined( '_JEXEC' ) or die( 'Restricted access' );

jimport('joomla.application.component.controller');

/**
 * Description of JoomlaCommunityPollsControllerPolls
 *
 * @author maverick
 */
class JoomlaCommunityPollsControllerPolls extends JController {
	function __construct(){
		parent::__construct();
        $this->registerTask( 'listpolls','getPollsList' );
        $this->registerTask( 'viewpoll','viewPoll' );
        $this->registerTask( 'castvote','castVote' );
	}

    function getPollsList(){
		$view = & $this->getView('polls', 'html');
		$model = & $this->getModel('polls');
		$view->setModel($model, true);
        $view->setLayout('list');
        $view->display();
    }

    function viewPoll(){
		$view = & $this->getView('polls', 'html');
		$model = & $this->getModel('polls');
		$view->setModel($model, true);
        $view->setLayout('viewpoll');
        $view->display();
    }

    function castVote(){
		$model = $this->getModel('polls');
		if ($model->castVote()){
            $message = JText::_('MSG_VOTE_SUCCESS');
        }else{
            $message = $model->getError();
        }
        $this->setRedirect('index.php?option=com_joomlacommunitypolls&controller=polls&task=list', $message);
    }
}
?>
